package yunhe.servlet;

import org.json.JSONArray;
import org.json.JSONObject;
import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.entity.Inventory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by lzh on 2017/6/17.
 */
@WebServlet(name = "GetInvServlet",urlPatterns = "/stockmgr/GetInvServlet")
public class GetInvServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String proBarCode=request.getParameter("proBarCode");
       
        System.out.println("进入servlet");
        if (proBarCode!=null){
            StockMgrBiz sb=new StockMgrBizImpl();
            List<Inventory> li=sb.searchInvByPro(proBarCode);
            JSONArray ja=new JSONArray();
            for (Inventory l:li){
                JSONObject jo=new JSONObject(l);
                ja.put(jo);
              
            }
            System.out.println("==========");
            System.out.println(ja.toString());
            response.getWriter().print(ja.toString());
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
